# -*- coding: utf-8 -*-

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from matplotlib.widgets import Button

fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], 'ro')
ax.set_xlim(0, 2*np.pi)
ax.set_ylim(-1, 1)

def update(frame):
    xdata.append(np.cos(frame * 0.1))
    ydata.append(np.sin(frame * 0.1))
    ln.set_data(xdata, ydata)

ani = FuncAnimation(fig, update)

def onclick(event):
    print('%s click: button=%d, x=%d, y=%d, xdata=%f, ydata=%f' %
          ('double' if event.dblclick else 'single', event.button,
           event.x, event.y, event.xdata, event.ydata))
           
def onclick2(event):
    print(event.x)
    print(event.y)
    print(event.xdata)
    print(event.ydata)

cid = fig.canvas.mpl_connect('button_press_event', onclick)
cid = fig.canvas.mpl_connect('motion_notify_event', onclick2)

rect = plt.axes([0.7, 0.05, 0.1, 0.075])
btn = Button(rect, 'Next')
@btn.on_clicked
def cb(event):
    print(event)

plt.show()